/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.rpc.xuelang.constants.enums;

import com.comac.ins.common.core.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 雪浪文件类型
 *
 * @author hxloongs
 * @date 2025-2-14
 */
@AllArgsConstructor
@Getter
public enum XueLangRenderFileTypeEnum {
    BDF("bdf", "bdf"),
    ZIP("zip", "zip压缩包");
    private final String value;
    private final String desc;

    public static String getDescByValue(String value) {
        XueLangRenderFileTypeEnum xuelangRenderFileTypeEnum = forValue(value);
        if (xuelangRenderFileTypeEnum == null) {
            return null;
        }
        return xuelangRenderFileTypeEnum.getDesc();
    }

    public static XueLangRenderFileTypeEnum forValue(String value) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        for (XueLangRenderFileTypeEnum xuelangRenderFileTypeEnum : XueLangRenderFileTypeEnum.values()) {
            if (xuelangRenderFileTypeEnum.getValue().equalsIgnoreCase(value)) {
                return xuelangRenderFileTypeEnum;
            }
        }
        return null;
    }

    public static XueLangRenderFileTypeEnum forDesc(String desc) {
        if (desc == null) {
            return null;
        }
        for (XueLangRenderFileTypeEnum xuelangRenderFileTypeEnum : XueLangRenderFileTypeEnum.values()) {
            if (desc.equals(xuelangRenderFileTypeEnum.getDesc())) {
                return xuelangRenderFileTypeEnum;
            }
        }
        return null;
    }

    public static XueLangRenderFileTypeEnum checkFileNameSuffix(String fileName) {
        if (StringUtils.isBlank(fileName)) {
            return null;
        }
        for (XueLangRenderFileTypeEnum xuelangRenderFileTypeEnum : XueLangRenderFileTypeEnum.values()) {
            if (fileName.endsWith(xuelangRenderFileTypeEnum.getValue()) || fileName.endsWith(xuelangRenderFileTypeEnum.getValue().toUpperCase())) {
                return xuelangRenderFileTypeEnum;
            }
        }
        return null;
    }

    public static Boolean checkFileNameIsZip(String fileName) {
        if (StringUtils.isBlank(fileName)) {
            return Boolean.FALSE;
        }
        if (fileName.endsWith(XueLangRenderFileTypeEnum.ZIP.getValue())
            || fileName.endsWith(XueLangRenderFileTypeEnum.ZIP.getValue().toUpperCase())) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }
}
